fusb302: Fairchild FUSB302B USB-C / USB-PD controller driver#2231
Open
b1nc0d3x wants to merge 1 commit into
Open
fusb302: Fairchild FUSB302B USB-C / USB-PD controller driver#2231b1nc0d3x wants to merge 1 commit into
b1nc0d3x wants to merge 1 commit into
Conversation
Add an in-tree driver for the Fairchild (now ON Semiconductor)
FUSB302B USB Type-C port controller. The chip is an i2c slave
implementing CC1/CC2 sensing, BMC PHY for USB Power Delivery
messages, DRP toggle for role detection, and a VBUS measure ADC.
It is the Type-C controller used on the RockPro64, Pinebook Pro,
ROCK Pi 4, Khadas Edge, and several Chromebook designs around the
RK3399 era.
The driver supplies the struct usbc_tcpc_ops vtable consumed by
the usbc(4) policy framework (D3). All PD message framing,
policy state, VDM negotiation, and DisplayPort altmode logic lives
in usbc; this driver is the chip-specific I2C / interrupt / FIFO
half.
Functional coverage:
- SRC + SNK port roles, with DRP toggle for autonomous role
discovery on cold plug.
- USB PD R3.2 messaging via the BMC TX/RX FIFOs (SOP only;
SOP'/SOP'' cable messages scaffolded but not exercised).
- Spec rev autoselect with PD 2.0 / PD 3.0 fallback (sysctl-
selectable for compatibility testing against picky sinks).
- Soft-reset and hard-reset paths.
- Polled DRP retoggle on lost partner -- recovers from sinks
that momentarily drop CC during their own re-orientation.
- IRQ-driven; uses sx(9) for the soft state and never holds a
spinlock across an I2C transaction.
- Debug output gated behind dev.fusb302.<N>.debug, default 0.
Modeled functionally on the Linux drivers/usb/typec/tcpm/fusb302.c
driver but is a clean reimplementation -- no code copied from
Linux. Linux is the reference for register sequencing only; the
state machine, locking discipline, and tunables are FreeBSD-native.
Includes a Rockchip-specific helper at
sys/arm64/rockchip/rk3399_fusb302_helper.c (built as a separate
module) that bridges FUSB302's role/orientation detection to the
RK3399 Type-C PHY mode-switch. This is the only Rockchip-specific
piece; the fusb302(4) driver itself runs on any platform that
exposes an i2c bus and a level-sensitive GPIO for INT_N.
Depends on D3 (usbc framework, PR freebsd#2211) being committed first.
Build will fail without D3 applied.
Signed-off-by: Kyle Crenshaw <B1nc0d3x@gmail.com>
|
Thank you for taking the time to contribute to FreeBSD! Some of files have special handling: Important @evadot wants to review changes to sys/arm64/rockchip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an in-tree driver for the Fairchild (now ON Semiconductor)
FUSB302B USB Type-C port controller. The chip is an i2c slave
that implements CC1/CC2 sensing, BMC PHY for USB Power Delivery
messages, DRP toggle for role detection, and a VBUS measure ADC.
It is the Type-C controller used on the RockPro64, Pinebook Pro,
ROCK Pi 4, Khadas Edge, and several Chromebook designs around the
RK3399 era.
The driver supplies the
struct usbc_tcpc_opsvtable consumed bythe
usbc(4)policy framework (D3, #2211). All PD messageframing, policy state, VDM negotiation, and DisplayPort altmode
logic lives in usbc; this driver is the chip-specific I2C /
interrupt / FIFO half.
Functional coverage:
discovery on cold plug.
SOP'/SOP'' cable messages scaffolded but not exercised).
selectable for compatibility testing against picky sinks).
that momentarily drop CC during their own re-orientation.
sx(9)for the soft state and never holdsa spinlock across an I2C transaction (FUSB302's transfers can
sleep on bus arbitration).
dev.fusb302.<N>.debug, default 0.Modeled functionally on the Linux
drivers/usb/typec/tcpm/fusb302.cdriver but is a cleanreimplementation -- no code copied from Linux. Linux is the
reference for register sequencing only; the state machine,
locking discipline, and tunables are FreeBSD-native.
Includes a Rockchip-specific helper at
sys/arm64/rockchip/rk3399_fusb302_helper.c(built as aseparate module) that bridges FUSB302's role/orientation
detection to the RK3399 Type-C PHY mode-switch. This file is the
only piece in the review that is Rockchip-specific; the
fusb302(4) driver itself runs on any platform that exposes an
i2c bus and a level-sensitive GPIO for INT_N.
Dependencies
Depends on D3 (
usbcframework, #2211) being committed first.The vtable consumed (
struct usbc_tcpc_ops,usbc_pd_policy_*entry points) is defined there. Build will fail without D3
applied.
What's deliberately NOT in this review
override beyond debug knobs) -- reserved for a follow-up.
Test plan
cold boot completes a full PD source contract (SRC_CAP ->
REQUEST -> ACCEPT -> PS_RDY) and a DP altmode entry within
~1.5 s of probe attach. Verified across 20+ plug/unplug
cycles; no leaked state, no IRQ storm (cf. D1, rk_gpio: implement PIC masking methods and mask unhandled IRQs #2197, the
rk_gpio PIC fix that makes this even reachable on cold boot).
PD source contract still completes; altmode entry is
correctly declined; downstream rk_typec_phy stays in USB
mode.
dev.fusb302.0.pd_spec_rev=20(PD 2.0only) on three different PD sinks (XYM W156F1, Anker 535
dock, a counterfeit Apple-pattern cable): all complete
contract without falling back further.
pd_spec_rev=30(PD 3.0) also completes on the W156F1 and the Anker but is
rejected by the counterfeit cable, which is expected.
dev.fusb302.0.force_hard_reset=1mid-contract. Driverreturns to USBC_PD_SRC_STARTUP and renegotiates within
300 ms.
kldload fusb302; kldload rk3399_fusb302_helper; kldunload rk3399_fusb302_helper; kldunload fusb302-- no leaks, nointerrupts left enabled at the controller, no spurious GPIO
edges observed under dtrace.
Size note
At ~4.5k lines this is on the larger side for a single
Differential. If reviewers prefer it split, the natural cut is:
fusb302.c+fusb302_var.h+sys/modules/fusb302/Makefile(the platform-independentdriver, ~4.4k lines).
rk3399_fusb302_helper.c+ its Makefile (Rockchip-specific extcon/typec-phy glue, ~140 lines).
I left it as one review because D4b is functionally meaningless
without D4a, and reviewing the helper in isolation is harder
than reviewing it as a small section of the same patch. Happy
to split on request.
Suggested reviewers
bsdimp, emaste, wulf7 (recent USB / iicbus committers per
git log); evadot, mhorne (sys/arm64/rockchip).